package com.atguigu.eud_teacher.service.impl;
import com.aliyuncs.DefaultAcsClient;
import com.atguigu.eud_teacher.util.VideoPropertiesUtils;
import com.atguigu.eud_teacher.util.initDefaultAcsClient;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoRequest;
import com.aliyuncs.vod.model.v20170321.GetPlayInfoResponse;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthRequest;
import com.aliyuncs.vod.model.v20170321.GetVideoPlayAuthResponse;
import com.atguigu.commonutils.exceptionhandler.GuliException;
import com.atguigu.eud_teacher.dao.VideoDao;
import com.atguigu.eud_teacher.entity.VideoEntity;
import com.atguigu.eud_teacher.feignclient.CourseFeignVideo;
import com.atguigu.eud_teacher.service.VideoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("videoService")
public class VideoServiceImpl extends ServiceImpl<VideoDao, VideoEntity> implements VideoService {


    @Resource
    private CourseFeignVideo courseFeignVideo;

    //多个视频id删除
    @Override
    public void removeVideoByCourseId(String courseId) {
        QueryWrapper<VideoEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("course_id", courseId);
        queryWrapper.select("video_source_id");
        List<VideoEntity> videoList = baseMapper.selectList(queryWrapper);
        List<String> videoIdList = new ArrayList<>();
        for (int i = 0; i < videoList.size(); i++) {
            VideoEntity videoEntity = videoList.get(i);
            String videoSourceId = videoEntity.getVideoSourceId();
            if (!videoSourceId.isEmpty()) {
                videoIdList.add(videoSourceId);
            }
        }
        if (videoIdList.size() > 0) {
            courseFeignVideo.deleteForBatch(videoIdList);
        }
        baseMapper.delete(new QueryWrapper<VideoEntity>().eq("course_id", courseId));
    }
}